#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1005;
const int MOD = 998244353;
const ll INF = 1e18;
int n, m;
int a[N];
int mx[N][N];
ll dp[N][N], cnt[N][N];
ll C[N][N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i + 1];
  n += 2;
  rep(i, 1, n) rep(j, i, n) mx[i][j] = max(mx[i][j - 1], a[j]);
  rep(i, 1, n - 1) {
    int j = i + 1;
    dp[i][j] = 0, cnt[i][j] = 1;
  }
  rep(i, 0, n) C[i][0] = C[i][i] = 1;
  rep(i, 1, n) rep(j, 1, i - 1) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;

  rep(len, 3, n) {
    rep(i, 1, n + 1 - len) {
      int j = i + len - 1;
      dp[i][j] = INF, cnt[i][j] = 0;
      rep(k, i + 1, j - 1) {
        ll x = mx[i + 1][k - 1] + mx[k + 1][j - 1] + dp[i][k] + dp[k][j];
        ll y = cnt[i][k] * cnt[k][j] % MOD;
        ll z = i + 1 == k ? 1 : (k + 1 == j ? 1 : C[j - i - 2][k - i - 1]);
        y = y * z % MOD;
        if (x < dp[i][j])
          dp[i][j] = x, cnt[i][j] = y;
        else if (x == dp[i][j])
          cnt[i][j] = (cnt[i][j] + y) % MOD;
      }
    }
  }
  cout << cnt[1][n];
  return 0;
}